#!/usr/bin/env python
#coding:utf-8
#非标准格式的POST获取页面
#获取这里的数据：http://www.yongyao.net/new/search1.aspx?parm=%E9%98%BF%E5%A5%87%E9%9C%89%E7%B4%A0

import urllib
import urllib2
import time

def savetofile(filename,buffer):
    fh=open(filename,'w')
    fh.write(buffer)
    fh.close()
    
def main():
    url=r'http://www.yongyao.net/ajax/yyaq.search1,yyaq.ashx?_method=Displaybind&_session=rw'
    for i in range(1,6):
        postdata='\n'.join(['page=%d' % i,'ypfl=2,3,','ypmc=阿奇霉素','sou=or'])
        req=urllib2.Request(url,data=postdata)
        html=urllib2.urlopen(req).read()
        savetofile('html%d.html' % i , html)
        print 'page %d ok' % i
        time.sleep(0.5)
    return 0

if __name__ == '__main__':
    main()
    print 'all done'
